/*
 * Author: http://www.redwolf-soft.com
 * All Rights Reserved
 * 
 * 2013.11
 *   
 * */

package com.redwolfsoft.libshoppingserver.brand;

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;

import net.sf.json.JSONObject;



public class CommentInfo {
	public final static String TAG = "CommentInfo";
	public String user = null;
	public long datetime = 0;//自1970年开始的UTC时间
	public String reviewContent = null;
	public String formattedDatatime = null;//服务器端不用赋值
	
	public CommentInfo(String user, long time, String review)
	{
		this.user = user;
		this.datetime = time;
		this.reviewContent = review;
		
		SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss",Locale.getDefault());
        Date date = new Date(time);
        formattedDatatime = sfd.format(date);
	}
	
	public CommentInfo(String user, String time, String review)
	{
		this.user = user;
		this.formattedDatatime = time;
		this.reviewContent = review;	
		
	}
	
	public CommentInfo(JSONObject obj)
	{
		if(obj==null)
		{
			//Log.w(TAG, "JSONObject is null");
			return;
		}
				
		user = obj.getString("user");
		datetime = obj.getLong("datetime");
			
		reviewContent = obj.getString("reviewContent");	
			
		SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss",Locale.getDefault());
	    Date date = new Date(datetime);
	    formattedDatatime = sfd.format(date);
	        
		
	}
	
	public JSONObject toJsonObject()
	{
		JSONObject obj = new JSONObject();
		//JSONObject obj2 = new JSONObject();
		//try {
			obj.put("user", user);
			obj.put("datetime", datetime);
			obj.put("reviewContent", reviewContent);			
			
			//obj2.put(TAG, obj);
		/*} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}*/
		return obj;
		
	}
}
